package com.guocheng.utils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileUtils {

    //默认存放文件路径
    private static String filePath = "";

    /**
     * 将文件存入写入文件中
     * @param file
     * @param bytes
     * @return
     * @throws IOException
     */
    public static boolean write(File file, byte[] bytes) throws IOException {
        if(file.exists()){
            file.mkdir();
        }
        FileOutputStream fileOutputStream = new FileOutputStream(file);
        fileOutputStream.write(bytes);
        fileOutputStream.close();
        return true;
    }

    /**
     * 将文件存入写入文件中
     * @param name
     * @param bytes
     * @return
     */
    public static boolean write(String name,byte[] bytes){
        File file = new File(filePath+name);
        try {
            return write(file,bytes);
        } catch (IOException e) {
            throw new RuntimeException("存储文件出错！",e);
        }
    }

}
